import "./index.css";

import HcPhotos from "HcPhotos";
import HcRender from "HcRender";
import { defaultAlt } from "utils/constant";
import { isArray, isString } from "utils/types";

const main = (function () {
    let hcPhotos: HcPhotos = null;
    return function (options: any) {
        if (hcPhotos) {
            return hcPhotos.reset(formatOptions(options));
        }

        hcPhotos = new HcPhotos(new HcRender(), formatOptions(options));
        return hcPhotos;
    }

    function formatOptions(options) {
        if (isArray(options)) {
            return {
                data: options
            }
        }

        if (isString(options)) {
            return {
                data: [{ src: options, alt: defaultAlt }]
            }
        }

        return options;
    }
}());

// window.hcPhotos = main;

export default main;